

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>pysimm.cassandra &mdash; pysimm 0.2 documentation</title>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  

  

  
    <link rel="top" title="pysimm 0.2 documentation" href="../../index.html"/>
        <link rel="up" title="pysimm" href="../pysimm.html"/> 

  
  <script src="../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../index.html" class="icon icon-home"> pysimm
          

          
          </a>

          
            
            
              <div class="version">
                0.2
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
                <ul>
<li class="toctree-l1"><a class="reference internal" href="../../pysimm.html">pysimm package</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../../index.html">pysimm</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          





<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../../index.html">Docs</a> &raquo;</li>
      
          <li><a href="../index.html">Module code</a> &raquo;</li>
      
          <li><a href="../pysimm.html">pysimm</a> &raquo;</li>
      
    <li>pysimm.cassandra</li>
      <li class="wy-breadcrumbs-aside">
        
          
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for pysimm.cassandra</h1><div class="highlight"><pre>
<span></span><span class="c1"># ******************************************************************************</span>
<span class="c1"># pysimm.cassandra module</span>
<span class="c1"># ******************************************************************************</span>
<span class="c1">#</span>
<span class="c1"># ******************************************************************************</span>
<span class="c1"># License</span>
<span class="c1"># ******************************************************************************</span>
<span class="c1"># The MIT License (MIT)</span>
<span class="c1">#</span>
<span class="c1"># Copyright (c) 2017 Alexander Demidov, Michael E. Fortunato, Coray M. Colina</span>
<span class="c1">#</span>
<span class="c1"># Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<span class="c1"># of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<span class="c1"># in the Software without restriction, including without limitation the rights</span>
<span class="c1"># to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<span class="c1"># copies of the Software, and to permit persons to whom the Software is</span>
<span class="c1"># furnished to do so, subject to the following conditions:</span>
<span class="c1">#</span>
<span class="c1"># The above copyright notice and this permission notice shall be included in</span>
<span class="c1"># all copies or substantial portions of the Software.</span>
<span class="c1">#</span>
<span class="c1"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<span class="c1"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span class="c1"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<span class="c1"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span class="c1"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<span class="c1"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</span>
<span class="c1"># THE SOFTWARE.</span>

<span class="kn">from</span> <span class="nn">StringIO</span> <span class="kn">import</span> <span class="n">StringIO</span>
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">call</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">types</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">Iterable</span><span class="p">,</span> <span class="n">OrderedDict</span>
<span class="kn">from</span> <span class="nn">pysimm</span> <span class="kn">import</span> <span class="n">system</span>
<span class="kn">from</span> <span class="nn">string</span> <span class="kn">import</span> <span class="n">ascii_uppercase</span>
<span class="kn">from</span> <span class="nn">pydoc</span> <span class="kn">import</span> <span class="n">locate</span>

<span class="n">DATA_PATH</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">relpath</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">realpath</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)),</span> <span class="s1">&#39;../dat/csndra_data&#39;</span><span class="p">))</span>

<span class="n">KCALMOL_2_K</span> <span class="o">=</span> <span class="mf">503.22271716452</span>

<span class="n">CASSANDRA_EXEC</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;CASSANDRA_EXEC&#39;</span><span class="p">)</span>

<span class="c1"># Creating a logger instance and send its output to console &#39;deafault&#39;</span>
<span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">,</span> <span class="n">datefmt</span><span class="o">=</span><span class="s1">&#39;%H:%M:%S&#39;</span><span class="p">,</span>
                    <span class="n">format</span><span class="o">=</span><span class="s1">&#39;</span><span class="si">%(asctime)s</span><span class="s1"> [</span><span class="si">%(levelname)s</span><span class="s1">]: </span><span class="si">%(message)s</span><span class="s1">&#39;</span><span class="p">)</span>

<span class="n">DEFAULT_PARAMS</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">&#39;Temperature_Info&#39;</span><span class="p">:</span> <span class="mi">300</span><span class="p">,</span>
    <span class="s1">&#39;Pressure_Info&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
    <span class="s1">&#39;Rcutoff_Low&#39;</span><span class="p">:</span> <span class="mf">0.1</span>
<span class="p">}</span>


<div class="viewcode-block" id="MCSimulation"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.MCSimulation">[docs]</a><span class="k">class</span> <span class="nc">MCSimulation</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.cassandra.MCSimulation</span>

<span class="sd">    Object containing the settings and the logic necessary to partially set-up an abstract Monte Carlo simulation</span>
<span class="sd">    to be submitted to the CASSANDRA software. The object also will include the simulation results once the simulations</span>
<span class="sd">    are finished.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        mc_sst (:class:`~pysimm.cassandra.McSystem`) : describes all molecules to be inserted by CASSANDRA</span>
<span class="sd">        init_sst (:class:`~pysimm.system.System`) : describes the optional initial fixed molecular configuration for MC</span>
<span class="sd">            simulations (default: empty cubic box with 1 nm side length). If the particles in the system are not</span>
<span class="sd">            attributed with the flag `is_fixed` all of them are considered to be fixed, and will be marked with this</span>
<span class="sd">            flag, otherwise all particles with is_fixed=False will be removed.</span>

<span class="sd">    Keyword Args:</span>
<span class="sd">        out_folder (str) : the relative path of the simulation results (all .dat, .mcf, as well as .chk, ... files will</span>
<span class="sd">            go there). If the folder does not exist it will be created with 0755 permissions.</span>
<span class="sd">        props_file (str) : the name of the  .inp file.</span>

<span class="sd">    Note:</span>
<span class="sd">        Other keyword arguments that are accepted are the GCMC simulation settings. The keywords of the settings</span>
<span class="sd">        are the same as they are described in CASSANDRA specification but without # symbol.</span>

<span class="sd">        **For example**: the keyword argument `Run_Name=&#39;my_simulation&#39;` will set `#Run_Name` setting in CASSANDRA</span>
<span class="sd">        input file to `my_simulation` value</span>

<span class="sd">    Parameters:</span>
<span class="sd">        props (dictionary) : include all simulation settings to be written to the CASSANDRA .inp file</span>
<span class="sd">        input (str) : text stream that will be written to the CASSANDRA .inp file</span>
<span class="sd">        tot_sst (:class:`~pysimm.system.System`) : object containing the results of CASSANDRA simulations</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mc_sst</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">init_sst</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">global</span> <span class="n">DATA_PATH</span>

        <span class="c1"># Initializing CASSANDRA input stream, empty at the beginning</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">input</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>

        <span class="c1"># Initializing dictionary that contains records that directly will be sent to the .inp file</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">&#39;MC Simulation&#39;</span><span class="p">)</span>

        <span class="c1"># Reading default properties of the GCMC simulations</span>
        <span class="n">def_dat</span> <span class="o">=</span> <span class="n">Cassandra</span><span class="p">(</span><span class="n">system</span><span class="o">.</span><span class="n">System</span><span class="p">())</span><span class="o">.</span><span class="n">read_input</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">DATA_PATH</span><span class="p">,</span> <span class="s1">&#39;mc_default.inp&#39;</span><span class="p">))</span>

        <span class="n">tmp</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;out_folder&#39;</span><span class="p">)</span>  <span class="c1"># Folder for the results and temporary files</span>
        <span class="k">if</span> <span class="n">tmp</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">out_folder</span> <span class="o">=</span> <span class="n">tmp</span>
            <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isabs</span><span class="p">(</span><span class="n">tmp</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">out_folder</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">relpath</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">out_folder</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">()</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">out_folder</span><span class="p">):</span>
            <span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">out_folder</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="mo">0755</span><span class="p">)</span>
        <span class="n">prefix</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Run_Name&#39;</span><span class="p">,</span> <span class="n">def_dat</span><span class="p">[</span><span class="s1">&#39;Run_Name&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Run_Name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Run_Name&#39;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">out_folder</span><span class="p">,</span> <span class="n">prefix</span><span class="p">),</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">props_file</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">out_folder</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;props_file&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">))</span>

        <span class="c1"># Simple (one-value) dynamic properties</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Temperature_Info&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Temperature_Info&#39;</span><span class="p">,</span>
                                                 <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Temperature_Info&#39;</span><span class="p">),</span> <span class="n">DEFAULT_PARAMS</span><span class="p">[</span><span class="s1">&#39;Temperature_Info&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Pair_Energy&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Pair_Energy&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Pair_Energy&#39;</span><span class="p">),</span> <span class="n">def_dat</span><span class="p">[</span><span class="s1">&#39;Pair_Energy&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Rcutoff_Low&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Rcutoff_Low&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Rcutoff_Low&#39;</span><span class="p">),</span> <span class="n">def_dat</span><span class="p">[</span><span class="s1">&#39;Rcutoff_Low&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Mixing_Rule&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Mixing_Rule&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Mixing_Rule&#39;</span><span class="p">),</span> <span class="n">def_dat</span><span class="p">[</span><span class="s1">&#39;Mixing_Rule&#39;</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Seed_Info&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Seed_Info&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Seed_Info&#39;</span><span class="p">),</span>
                                          <span class="p">[</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="mf">1e+7</span><span class="p">),</span> <span class="nb">int</span><span class="p">(</span><span class="mf">1e+8</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)),</span>
                                           <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="mf">1e+7</span><span class="p">),</span> <span class="nb">int</span><span class="p">(</span><span class="mf">1e+8</span> <span class="o">-</span> <span class="mi">1</span><span class="p">))])</span>

        <span class="c1"># Multiple-value one/many line dynamic properties</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Run_Type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Run_Type&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Run_Type&#39;</span><span class="p">),</span> <span class="n">def_dat</span><span class="p">[</span><span class="s1">&#39;Run_Type&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Charge_Style&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Charge_Style&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Charge_Stylemc&#39;</span><span class="p">),</span> <span class="n">def_dat</span><span class="p">[</span><span class="s1">&#39;Charge_Style&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;VDW_Style&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;VDW_Style&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;VDW_Style&#39;</span><span class="p">),</span> <span class="n">def_dat</span><span class="p">[</span><span class="s1">&#39;VDW_Style&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Simulation_Length_Info&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Simulation_Length_Info&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Simulation_Length_Info&#39;</span><span class="p">),</span>
                                                       <span class="n">def_dat</span><span class="p">[</span><span class="s1">&#39;Simulation_Length_Info&#39;</span><span class="p">],</span>
                                                       <span class="o">**</span><span class="p">{</span><span class="s1">&#39;write_headers&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span> <span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;CBMC_Info&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;CBMC_Info&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;CBMC_Info&#39;</span><span class="p">),</span> <span class="n">def_dat</span><span class="p">[</span><span class="s1">&#39;CBMC_Info&#39;</span><span class="p">],</span>
                                          <span class="o">**</span><span class="p">{</span><span class="s1">&#39;write_headers&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span> <span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">})</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Box_Info&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Box_Info&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Box_Info&#39;</span><span class="p">),</span> <span class="n">def_dat</span><span class="p">[</span><span class="s1">&#39;Box_Info&#39;</span><span class="p">],</span> <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Property_Info 1&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Property_Info 1&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Property_Info&#39;</span><span class="p">),</span> <span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">})</span>

        <span class="c1"># Setting the simulation total system</span>
        <span class="k">if</span> <span class="n">init_sst</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span> <span class="o">=</span> <span class="n">init_sst</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">center</span><span class="p">(</span><span class="s1">&#39;box&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="bp">True</span><span class="p">)</span>  <span class="c1"># the center of the calculation box should be at origin</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;The frame generating system for Monte-Carlo simulations is not set. &#39;</span>
                                <span class="s1">&#39;Creating empty cubic box of 1 nm size&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span> <span class="o">=</span> <span class="n">system</span><span class="o">.</span><span class="n">System</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">forcefield</span> <span class="o">=</span> <span class="s1">&#39;trappe/amber&#39;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">dim</span> <span class="o">=</span> <span class="n">system</span><span class="o">.</span><span class="n">Dimension</span><span class="p">(</span><span class="n">dx</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">dy</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">dz</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>

        <span class="c1"># Molecule configuration files describing all species of the system.</span>
        <span class="c1"># They are **absolutely** needed to start calculation</span>
        <span class="n">mol_files</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>

        <span class="c1"># Some necessary verification of obtained system</span>
        <span class="c1"># TODO: check the forcefield to be sure that it is claas 1</span>
        <span class="k">if</span> <span class="bp">False</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;CASSANDRA supports only 1-st class force fields&#39;</span><span class="p">)</span>
            <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">zero_charge</span><span class="p">()</span>  <span class="c1"># the sum of the charges should necessary be 0</span>

        <span class="c1"># Creating the system of fixed molecules</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst_mcfile</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;fixed_sst&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst_mcfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">out_folder</span><span class="p">,</span> <span class="s1">&#39;fixed_syst.mcf&#39;</span><span class="p">)</span>
            <span class="n">mol_files</span><span class="p">[</span><span class="s1">&#39;file1&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst_mcfile</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>

        <span class="c1"># Setting up the Monte Carlo system</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mc_sst</span> <span class="o">=</span> <span class="n">mc_sst</span>
        <span class="k">if</span> <span class="n">mc_sst</span><span class="p">:</span>
            <span class="n">mc_sst</span><span class="o">.</span><span class="n">file_store</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">out_folder</span>
            <span class="n">mol_files</span> <span class="o">=</span> <span class="n">mc_sst</span><span class="o">.</span><span class="n">update_props</span><span class="p">(</span><span class="n">mol_files</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Molecule_Files&#39;</span><span class="p">):</span>
            <span class="n">mol_files</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Molecule_Files&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">items</span><span class="p">()))</span>

        <span class="c1"># Raising an error and stop execution if no MCF information in one or another way is provided</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">mc_sst</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="ow">not</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Molecule_Files&#39;</span><span class="p">)):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;The molecular configuration files of gas molecules for simulation are not set. &#39;</span>
                              <span class="s1">&#39;Nothing to simulate. Exiting...&#39;</span><span class="p">)</span>
            <span class="nb">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">mol_files</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Nbr_Species&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Nbr_Species&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Molecule_Files&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Molecule_Files&#39;</span><span class="p">,</span> <span class="n">mol_files</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">})</span>

        <span class="c1"># Synchronzing &quot;start type&quot; .inp record</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst_xyz</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
        <span class="n">pops_list</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span>
        <span class="n">start_type</span> <span class="o">=</span> <span class="s1">&#39;make_config&#39;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">:</span>
            <span class="n">pops_list</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst_xyz</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">out_folder</span><span class="p">,</span> <span class="s1">&#39;fixed_syst.xyz&#39;</span><span class="p">)</span>
            <span class="n">start_type</span> <span class="o">=</span> <span class="s1">&#39;read_config&#39;</span>
        <span class="n">start_conf_dict</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;start_type&#39;</span><span class="p">,</span> <span class="n">start_type</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;species&#39;</span><span class="p">,</span> <span class="n">pops_list</span><span class="p">),</span>
                                       <span class="p">(</span><span class="s1">&#39;file_name&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst_xyz</span><span class="p">)])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Start_Type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Start_Type&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Start_Type&#39;</span><span class="p">),</span> <span class="n">start_conf_dict</span><span class="p">)</span>

        <span class="c1"># Synchronzing Fragment files:</span>
        <span class="n">frag_files</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">mc_sst</span><span class="p">:</span>
            <span class="n">mc_sst</span><span class="o">.</span><span class="n">temperature</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Temperature_Info&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</span>
            <span class="n">frag_files</span> <span class="o">=</span> <span class="n">mc_sst</span><span class="o">.</span><span class="n">update_frag_record</span><span class="p">(</span><span class="n">frag_files</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Fragment_Files&#39;</span><span class="p">):</span>
            <span class="n">frag_files</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Fragment_Files&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">items</span><span class="p">()))</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">mc_sst</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="ow">not</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Fragment_Files&#39;</span><span class="p">)):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Cannot set the fragment files of gas molecules for simulation&#39;</span><span class="p">)</span>
            <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Fragment_Files&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Fragment_Files&#39;</span><span class="p">,</span> <span class="n">frag_files</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">})</span>

<div class="viewcode-block" id="MCSimulation.write"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.MCSimulation.write">[docs]</a>    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.MCSimulation.write</span>

<span class="sd">        Iterates through the :class:`~MCSimulation.props` dictionary creating the text for correct CASSANDRA input</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">value</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">input</span> <span class="o">+=</span> <span class="s1">&#39;{:}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">to_string</span><span class="p">())</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">input</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">END&#39;</span>
        <span class="c1"># Initializing output stream</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Writing CASSANDRA .inp file to &quot;{:}&quot;...&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">props_file</span><span class="p">))</span>
        <span class="n">out_stream</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">props_file</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span>
        <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">input</span><span class="p">))</span>
        <span class="n">out_stream</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;File: &quot;{:}&quot; was created sucsessfully&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">props_file</span><span class="p">))</span></div>

<div class="viewcode-block" id="MCSimulation.group_by_id"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.MCSimulation.group_by_id">[docs]</a>    <span class="k">def</span> <span class="nf">group_by_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">group_key</span><span class="o">=</span><span class="s1">&#39;matrix&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.MCSimulation.group_by_id</span>

<span class="sd">        Method groups the atoms of the system :class:`~MCSimulation.tot_sst` by a certain property. Will iterate through</span>
<span class="sd">        all atoms in the system and return indexes of only those atoms that match the property. Currently supports 3</span>
<span class="sd">        properties defined by the input keyword argument argument.</span>

<span class="sd">        Keyword Args:</span>
<span class="sd">            group_key (str): text constant defines the property to match. Possible keywords are:</span>

<span class="sd">                (1) `matrix` -- (default) indexes of the atoms in :obj:`~MCSimulation.fxd_sst`</span>

<span class="sd">                (2) `rigid` -- indexes of all atoms that have rigid atomic bonds. It is assumed here that rigid and</span>
<span class="sd">                    nonrigid atoms can interact only through intermolecular forces</span>

<span class="sd">                (3) `nonrigid` -- opposite of previous, indexes of all atoms that have nonrigid atomic bonds</span>

<span class="sd">        Returns:</span>
<span class="sd">            str:</span>
<span class="sd">                string in format `a1:b1 a2:b2 ...` where all indexes inside `[ak, bk]` belongs to the selected group</span>
<span class="sd">                and array of the form `[[a1, b1], [a2, b2], ...]`</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">fxd_sst_idxs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">:</span>
            <span class="n">fxd_sst_idxs</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="o">.</span><span class="n">particles</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
        <span class="c1"># Behaviour depending on type of particles to check</span>
        <span class="n">check</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span>
        <span class="k">if</span> <span class="n">group_key</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;nonrigid&#39;</span><span class="p">:</span>
            <span class="n">check</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="ow">not</span> <span class="n">x</span><span class="o">.</span><span class="n">is_rigid</span>
        <span class="k">elif</span> <span class="n">group_key</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;rigid&#39;</span><span class="p">:</span>
            <span class="n">check</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">is_rigid</span>
        <span class="k">elif</span> <span class="n">group_key</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;matrix&#39;</span><span class="p">:</span>
            <span class="n">check</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">tag</span> <span class="ow">in</span> <span class="n">fxd_sst_idxs</span>
        <span class="n">idx_array</span> <span class="o">=</span> <span class="p">[[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]]</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">check</span><span class="p">(</span><span class="n">p</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">idx_array</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">tag</span> <span class="o">-</span> <span class="n">idx_array</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                        <span class="n">idx_array</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">])</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">idx_array</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">tag</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">idx_array</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
        <span class="n">idx_string</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">idx_array</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">t</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">t</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">idx_string</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">+</span> <span class="s1">&#39;:&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">+</span> <span class="s1">&#39; &#39;</span>
        <span class="k">return</span> <span class="n">idx_string</span><span class="p">,</span> <span class="n">idx_array</span></div>

<div class="viewcode-block" id="MCSimulation.upd_simulation"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.MCSimulation.upd_simulation">[docs]</a>    <span class="k">def</span> <span class="nf">upd_simulation</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.MCSimulation.upd_simulation</span>

<span class="sd">        Updates the :class:`~MCSimulation.tot_sst` field using the `MCSimulation.props[&#39;Run_Name&#39;].chk` file. Will try</span>
<span class="sd">        to parse the checkpoint file and read the coordinates of the molecules inserted by CASSANDRA. If neither of the</span>
<span class="sd">        molecules from the :class:`~MCSimulation.mc_sst` can be fit to the text that was read the method will raise an</span>
<span class="sd">        exception. The fitting method: :class:`~McSystem.make_system` assumes that different molecules inserted by</span>
<span class="sd">        CASSANDRA have the same order of the atoms.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">fname</span> <span class="o">=</span> <span class="s1">&#39;{:}{:}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Run_Name&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="s1">&#39;.chk&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Updating MC system from the CASSANDRA {:} file...&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">fname</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">fname</span><span class="p">):</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">inp</span><span class="p">:</span>
                    <span class="n">lines</span> <span class="o">=</span> <span class="n">inp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
                    <span class="c1"># Define the starting index of the lines with inserted atoms</span>
                    <span class="n">start_ind</span> <span class="o">=</span> <span class="n">lines</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;total number of molecules&#39;</span><span class="p">)</span>
                    <span class="n">end_ind</span> <span class="o">=</span> <span class="n">start_ind</span> <span class="o">+</span> <span class="n">lines</span><span class="p">[</span><span class="n">start_ind</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;****&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
                    <span class="n">count_info</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="n">start_ind</span><span class="p">:</span><span class="n">end_ind</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
                    <span class="n">offset</span> <span class="o">=</span> <span class="mi">1</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">:</span>
                        <span class="n">tmp</span> <span class="o">=</span> <span class="n">count_info</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                        <span class="n">offset</span> <span class="o">+=</span> <span class="nb">int</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="o">.</span><span class="n">particles</span><span class="p">)</span>
                    <span class="c1"># Grab the lines with inserted atoms</span>
                    <span class="n">start_ind</span> <span class="o">=</span> <span class="n">lines</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;coordinates for all the boxes&#39;</span><span class="p">)</span>
                    <span class="n">all_coord_lines</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="n">start_ind</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
                    <span class="n">inp</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mc_sst</span><span class="o">.</span><span class="n">make_system</span><span class="p">(</span><span class="n">all_coord_lines</span><span class="p">[</span><span class="n">offset</span><span class="p">:]),</span> <span class="n">change_dim</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Simulation system successfully updated&#39;</span><span class="p">)</span>

            <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Cannot fit the molecules from the CASSANDRA file to the PySIMM system&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Cannot find the CASSANDRA checkpoint file to update simulation. &#39;</span>
                              <span class="s1">&#39;Probably it cannot be written by CASSANDRA to the place you specified&#39;</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">__check_params__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.MCSimulation.__check_params__</span>

<span class="sd">        Private method designed for update the fields of the simulation object to make them conformed with each other</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Sync the simulation box parameters</span>
        <span class="n">dx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">xlo</span>
        <span class="n">dy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">yhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">ylo</span>
        <span class="n">dz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zhi</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">zlo</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">dx</span> <span class="o">==</span> <span class="n">dy</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">dy</span> <span class="o">==</span> <span class="n">dz</span><span class="p">):</span>
            <span class="n">box_type</span> <span class="o">=</span> <span class="s1">&#39;cubic&#39;</span>
            <span class="n">box_dims</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">dx</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">box_type</span> <span class="o">=</span> <span class="s1">&#39;orthogonal&#39;</span>
            <span class="n">box_dims</span> <span class="o">=</span> <span class="s1">&#39;{0:} {1:} {2:}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">,</span> <span class="n">dz</span><span class="p">)</span>

        <span class="n">upd_vals</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;box_count&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                                <span class="p">(</span><span class="s1">&#39;box_type&#39;</span><span class="p">,</span> <span class="n">box_type</span><span class="p">),</span>
                                <span class="p">(</span><span class="s1">&#39;box_size&#39;</span><span class="p">,</span> <span class="n">box_dims</span><span class="p">)])</span>
        <span class="k">if</span> <span class="p">(</span><span class="s1">&#39;Box_Info&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Box_Info&#39;</span><span class="p">],</span> <span class="n">InpSpec</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Box_Info&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Box_Info&#39;</span><span class="p">,</span> <span class="n">upd_vals</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">})</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Box_Info&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">upd_vals</span>

        <span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Box_Info&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</span><span class="p">[</span><span class="s1">&#39;box_size&#39;</span><span class="p">]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Box_Info&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</span><span class="p">[</span><span class="s1">&#39;box_type&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;cubic&#39;</span><span class="p">:</span>
            <span class="n">tmp</span> <span class="o">=</span> <span class="p">[</span><span class="n">tmp</span><span class="p">]</span> <span class="o">*</span> <span class="mi">3</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">dim</span> <span class="o">=</span> <span class="n">system</span><span class="o">.</span><span class="n">Dimension</span><span class="p">(</span><span class="n">center</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">dx</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="n">dy</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="n">dz</span><span class="o">=</span><span class="nb">float</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>

        <span class="c1"># Sync of the volume change frecuency in equilibration regime</span>
        <span class="k">if</span> <span class="s1">&#39;Prob_Volume&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Prob_Volume&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Run_Type&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</span><span class="p">[</span><span class="s1">&#39;steps&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Run_Type&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</span><span class="p">[</span><span class="s1">&#39;steps&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">__write_chk__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">out_file</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.MCSimulation.__write_chk__</span>

<span class="sd">        Creates the CASSANDRA checkpoint file basing on the information from the `~MCSimulation.tot_sst` field</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Initializing output stream</span>
        <span class="k">if</span> <span class="n">out_file</span> <span class="o">==</span> <span class="s1">&#39;string&#39;</span><span class="p">:</span>
            <span class="n">out_stream</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">out_stream</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">out_file</span><span class="p">,</span> <span class="s1">&#39;w+&#39;</span><span class="p">)</span>
        <span class="n">blk_separ</span> <span class="o">=</span> <span class="s1">&#39; {:*^75}</span><span class="se">\n</span><span class="s1">&#39;</span>

        <span class="c1"># Writing Translation/rotation/... info</span>
        <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">blk_separ</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;Translation,rotation, dihedral, angle distortion&#39;</span><span class="p">))</span>
        <span class="n">tmplate</span> <span class="o">=</span> <span class="s1">&#39;{t[0]$$}{t[1]$$}{t[2]$$}{t[3]$$}{t[4]$$}</span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="n">molecules</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Molecule_Files&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</span>
        <span class="k">for</span> <span class="n">m</span><span class="p">,</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">molecules</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">molecules</span><span class="p">))):</span>
            <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">tmplate</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;$$&#39;</span><span class="p">,</span> <span class="s1">&#39;:&gt;6d&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">t</span><span class="o">=</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]))</span>
            <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">tmplate</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;$$&#39;</span><span class="p">,</span> <span class="s1">&#39;:&gt;6d&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">t</span><span class="o">=</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]))</span>
            <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{t[0]:&gt;23.14E}{t[2]:&gt;23.14E}{t[2]:&gt;23.14E}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">t</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]))</span>
            <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{0:&gt;12d}{0:&gt;12d}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>

        <span class="c1"># Small section with total # of MC trials -- it is 0 at the beginning</span>
        <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">blk_separ</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;# of MC steps&#39;</span><span class="p">))</span>
        <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:&gt;12d}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>

        <span class="c1"># Writing Box-info information</span>
        <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">blk_separ</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;Box info&#39;</span><span class="p">))</span>
        <span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Box_Info&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</span><span class="p">[</span><span class="s1">&#39;box_size&#39;</span><span class="p">]</span>
        <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>
        <span class="n">bx_type</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="n">types</span><span class="o">.</span><span class="n">ListType</span><span class="p">):</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">:</span>
                <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">tmp</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">tmp</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">tmp</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="nb">float</span><span class="p">):</span>
            <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">tmp</span><span class="p">,</span> <span class="n">tmp</span><span class="p">,</span> <span class="n">tmp</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="nb">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>

        <span class="c1"># First 0 here correspond to the # of trials</span>
        <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{0:&gt;12d}</span><span class="se">\n</span><span class="s1">{1:&lt;18.10f}</span><span class="se">\n</span><span class="s1">{2:}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">x</span> <span class="o">*</span> <span class="n">y</span> <span class="o">*</span> <span class="n">z</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Box_Info&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</span><span class="p">[</span><span class="s1">&#39;box_type&#39;</span><span class="p">]))</span>

        <span class="n">tmpl</span> <span class="o">=</span> <span class="s1">&#39;{t[0]&amp;&amp;}{t[1]&amp;&amp;}{t[2]&amp;&amp;}</span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="n">tmp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">diag</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">lines</span> <span class="ow">in</span> <span class="n">tmp</span><span class="p">:</span>
            <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">((</span><span class="n">tmpl</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;&amp;&amp;&#39;</span><span class="p">,</span> <span class="s1">&#39;:^22.14f&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">t</span><span class="o">=</span><span class="n">lines</span><span class="p">))</span>

        <span class="n">tmp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">diag</span><span class="p">([</span><span class="mi">1</span> <span class="o">/</span> <span class="n">x</span><span class="p">,</span> <span class="mi">1</span> <span class="o">/</span> <span class="n">y</span><span class="p">,</span> <span class="mi">1</span> <span class="o">/</span> <span class="n">z</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">lines</span> <span class="ow">in</span> <span class="n">tmp</span><span class="p">:</span>
            <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">((</span><span class="n">tmpl</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;&amp;&amp;&#39;</span><span class="p">,</span> <span class="s1">&#39;:^22.8f&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">t</span><span class="o">=</span><span class="n">lines</span><span class="p">))</span>
        <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:&gt;18.12f}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>

        <span class="c1"># Creating seeds</span>
        <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">blk_separ</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;SEEDS&#39;</span><span class="p">))</span>
        <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{t[0]:&gt;12d}{t[1]:&gt;12d}{t[2]:&gt;12d}</span><span class="se">\n</span><span class="s1">{t[3]:&gt;12d}{t[4]:&gt;12d}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="n">t</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_integers</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="mf">1e+7</span><span class="p">),</span> <span class="nb">int</span><span class="p">(</span><span class="mf">1e+8</span> <span class="o">-</span> <span class="mi">1</span><span class="p">),</span> <span class="mi">5</span><span class="p">)))</span>

        <span class="c1"># Writing total number of molecules by species</span>
        <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">blk_separ</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;Info for total number of molecules&#39;</span><span class="p">))</span>
        <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{0:&gt;11d}{1:&gt;11d}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>  <span class="c1"># Currentely only one polymer &quot;molecule&quot; in the simulation</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">molecules</span><span class="p">)):</span>
            <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{0:&gt;11d}{1:&gt;11d}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>

        <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">blk_separ</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;Writing coordinates of all boxes&#39;</span><span class="p">))</span>
        <span class="c1"># Writing coordinates of atoms in all boxes</span>
        <span class="n">line_template</span> <span class="o">=</span> <span class="s1">&#39;{l[0]:&lt;5}{l[1]:&lt;25.15f}{l[2]:&lt;25.15f}{l[3]:&lt;25.15f}{l[4]:&gt;10d}</span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="k">for</span> <span class="n">parts</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line_template</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">l</span><span class="o">=</span><span class="p">[</span><span class="n">parts</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">parts</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">parts</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">parts</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="mi">1</span><span class="p">]))</span>
            <span class="k">except</span><span class="p">:</span>
                <span class="k">continue</span>
        <span class="n">out_stream</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>


<div class="viewcode-block" id="GCMC"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.GCMC">[docs]</a><span class="k">class</span> <span class="nc">GCMC</span><span class="p">(</span><span class="n">MCSimulation</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.cassandra.GCMC</span>
<span class="sd">    Initiates the specific type of Monte Carlo simulations for CASSANDRA: simulations using Grand-Canonical ensemble of</span>
<span class="sd">    particles (constant volume-temperature-chemical potential, muVT). See :class:`~pysimm.cassandra.MCSimulation`</span>
<span class="sd">    for the detailed description of the properties.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mc_sst</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">init_sst</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">MCSimulation</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mc_sst</span><span class="p">,</span> <span class="n">init_sst</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;GCMC&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Sim_Type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Sim_Type&#39;</span><span class="p">,</span> <span class="s1">&#39;GCMC&#39;</span><span class="p">,</span> <span class="s1">&#39;gcmc&#39;</span><span class="p">)</span>

        <span class="c1"># Path for all intermediate Cassandra files and results</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props_file</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">out_folder</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;props_file&#39;</span><span class="p">,</span> <span class="s1">&#39;gcmc_input.inp&#39;</span><span class="p">))</span>

        <span class="n">add</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">:</span>
            <span class="n">add</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Chemical_Potential_Info&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Chemical_Potential_Info&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;chem_pot&#39;</span><span class="p">),</span>
                                                        <span class="o">-</span><span class="mi">30</span> <span class="o">*</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span> <span class="o">-</span> <span class="n">add</span><span class="p">))</span>

        <span class="c1"># Order of the next four items is IMPORTANT! Check the CASSANDRA spec file for further info</span>
        <span class="n">def_init_prob</span> <span class="o">=</span> <span class="mf">0.25</span>
        <span class="n">limits</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.3</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">:</span>
            <span class="n">limits</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Prob_Translation&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpProbSpec</span><span class="p">(</span><span class="s1">&#39;Prob_Translation&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Prob_Translation&#39;</span><span class="p">),</span>
                                                     <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;tot_prob&#39;</span><span class="p">,</span> <span class="n">def_init_prob</span><span class="p">),</span>
                                                                  <span class="p">(</span><span class="s1">&#39;limit_vals&#39;</span><span class="p">,</span> <span class="n">limits</span><span class="p">)]),</span>
                                                     <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span> <span class="s1">&#39;indicator&#39;</span><span class="p">:</span> <span class="s1">&#39;start&#39;</span><span class="p">})</span>
        <span class="n">tps</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;cbmc&#39;</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">:</span>
            <span class="n">tps</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;none&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Prob_Insertion&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpProbSpec</span><span class="p">(</span><span class="s1">&#39;Prob_Insertion&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Prob_Insertion&#39;</span><span class="p">),</span>
                                                   <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;tot_prob&#39;</span><span class="p">,</span> <span class="n">def_init_prob</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;types&#39;</span><span class="p">,</span> <span class="n">tps</span><span class="p">)]),</span>
                                                   <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">})</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Prob_Deletion&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpProbSpec</span><span class="p">(</span><span class="s1">&#39;Prob_Deletion&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Prob_Deletion&#39;</span><span class="p">),</span> <span class="n">def_init_prob</span><span class="p">)</span>

        <span class="n">max_ang</span> <span class="o">=</span> <span class="p">[</span><span class="mi">180</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">:</span>
            <span class="n">max_ang</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Prob_Rotation&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpProbSpec</span><span class="p">(</span><span class="s1">&#39;Prob_Rotation&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Prob_Rotation&#39;</span><span class="p">),</span>
                                                  <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;tot_prob&#39;</span><span class="p">,</span> <span class="n">def_init_prob</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;limit_vals&#39;</span><span class="p">,</span> <span class="n">max_ang</span><span class="p">)]),</span>
                                                  <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span>  <span class="s1">&#39;indicator&#39;</span><span class="p">:</span> <span class="s1">&#39;end&#39;</span><span class="p">})</span></div>


<div class="viewcode-block" id="NVT"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.NVT">[docs]</a><span class="k">class</span> <span class="nc">NVT</span><span class="p">(</span><span class="n">MCSimulation</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.cassandra.NVT</span>
<span class="sd">    Initiates the specific type of Monte Carlo simulations for CASSANDRA: simulations using Canonical ensemble of</span>
<span class="sd">    particles (constant volume-temperature-number of particles, NVT). See :class:`~pysimm.cassandra.MCSimulation`</span>
<span class="sd">    for the detailed description of the properties.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mc_sst</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">init_sst</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">MCSimulation</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mc_sst</span><span class="p">,</span> <span class="n">init_sst</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;NVT&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props_file</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">out_folder</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;props_file&#39;</span><span class="p">,</span> <span class="s1">&#39;nvt-mc_input.inp&#39;</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Sim_Type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Sim_Type&#39;</span><span class="p">,</span> <span class="s1">&#39;nvt_mc&#39;</span><span class="p">,</span> <span class="s1">&#39;nvt_mc&#39;</span><span class="p">)</span>

        <span class="n">move_probs</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
        <span class="n">limits</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.3</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">:</span>
            <span class="n">limits</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Prob_Translation&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpProbSpec</span><span class="p">(</span><span class="s1">&#39;Prob_Translation&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Prob_Translation&#39;</span><span class="p">),</span>
                                                     <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;tot_prob&#39;</span><span class="p">,</span> <span class="n">move_probs</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
                                                                  <span class="p">(</span><span class="s1">&#39;limit_vals&#39;</span><span class="p">,</span> <span class="n">limits</span><span class="p">)]),</span>
                                                     <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span> <span class="s1">&#39;indicator&#39;</span><span class="p">:</span> <span class="s1">&#39;start&#39;</span><span class="p">})</span>
        <span class="n">sub_probs</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">:</span>
            <span class="n">sub_probs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">sm</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">sub_probs</span><span class="p">)</span>
        <span class="n">sub_probs</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span> <span class="o">/</span> <span class="n">sm</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">sub_probs</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Prob_Regrowth&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpProbSpec</span><span class="p">(</span><span class="s1">&#39;Prob_Regrowth&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Prob_Regrowth&#39;</span><span class="p">),</span>
                                                  <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;tot_prob&#39;</span><span class="p">,</span> <span class="n">move_probs</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="p">(</span><span class="s1">&#39;sub_probs&#39;</span><span class="p">,</span> <span class="n">sub_probs</span><span class="p">)]),</span>
                                                  <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">})</span>
        <span class="n">max_ang</span> <span class="o">=</span> <span class="p">[</span><span class="mi">180</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">:</span>
            <span class="n">max_ang</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Prob_Rotation&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpProbSpec</span><span class="p">(</span><span class="s1">&#39;Prob_Rotation&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Prob_Rotation&#39;</span><span class="p">),</span>
                                                  <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;tot_prob&#39;</span><span class="p">,</span> <span class="n">move_probs</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="p">(</span><span class="s1">&#39;limit_vals&#39;</span><span class="p">,</span> <span class="n">max_ang</span><span class="p">)]),</span>
                                                  <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span> <span class="s1">&#39;indicator&#39;</span><span class="p">:</span> <span class="s1">&#39;end&#39;</span><span class="p">})</span></div>


<div class="viewcode-block" id="NPT"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.NPT">[docs]</a><span class="k">class</span> <span class="nc">NPT</span><span class="p">(</span><span class="n">MCSimulation</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.cassandra.NPT</span>
<span class="sd">    Initiates the specific type of Monte Carlo simulations for CASSANDRA: simulations using Isobaric-Isothermal ensemble</span>
<span class="sd">    of particles (NPT). See :class:`~pysimm.cassandra.MCSimulation` for the detailed description of the properties.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mc_sst</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">init_sst</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">MCSimulation</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mc_sst</span><span class="p">,</span> <span class="n">init_sst</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="c1"># Initialising object attributes</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;NPT&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props_file</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">out_folder</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;props_file&#39;</span><span class="p">,</span> <span class="s1">&#39;npt-mc_input.inp&#39;</span><span class="p">))</span>

        <span class="c1"># Initialising simulation-specific props attribute</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Sim_Type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Sim_Type&#39;</span><span class="p">,</span> <span class="s1">&#39;npt_mc&#39;</span><span class="p">,</span> <span class="s1">&#39;npt_mc&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Pressure_Info&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpSpec</span><span class="p">(</span><span class="s1">&#39;Pressure_Info&#39;</span><span class="p">,</span>
                                              <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Pressure_Info&#39;</span><span class="p">),</span> <span class="n">DEFAULT_PARAMS</span><span class="p">[</span><span class="s1">&#39;Pressure_Info&#39;</span><span class="p">])</span>

        <span class="n">move_probs</span> <span class="o">=</span> <span class="p">[</span><span class="o">.</span><span class="mi">34</span><span class="p">,</span> <span class="o">.</span><span class="mo">02</span><span class="p">,</span> <span class="o">.</span><span class="mi">32</span><span class="p">,</span> <span class="o">.</span><span class="mi">32</span><span class="p">]</span>

        <span class="n">limits</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.3</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">:</span>
            <span class="n">limits</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Prob_Translation&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpProbSpec</span><span class="p">(</span><span class="s1">&#39;Prob_Translation&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Prob_Translation&#39;</span><span class="p">),</span>
                                                     <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;tot_prob&#39;</span><span class="p">,</span> <span class="n">move_probs</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
                                                                  <span class="p">(</span><span class="s1">&#39;limit_vals&#39;</span><span class="p">,</span> <span class="n">limits</span><span class="p">)]),</span>
                                                     <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span> <span class="s1">&#39;indicator&#39;</span><span class="p">:</span> <span class="s1">&#39;start&#39;</span><span class="p">})</span>
        <span class="n">vol_margins</span> <span class="o">=</span> <span class="mf">0.1</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Box_Info&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</span><span class="p">[</span><span class="s1">&#39;box_size&#39;</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Prob_Volume&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpProbSpec</span><span class="p">(</span><span class="s1">&#39;Prob_Volume&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Prob_Volume&#39;</span><span class="p">),</span>
                                                <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;tot_prob&#39;</span><span class="p">,</span> <span class="n">move_probs</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="p">(</span><span class="s1">&#39;types&#39;</span><span class="p">,</span> <span class="n">vol_margins</span><span class="p">)]),</span>
                                                <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">})</span>
        <span class="n">sub_probs</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">:</span>
            <span class="n">sub_probs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">sm</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">sub_probs</span><span class="p">)</span>
        <span class="n">sub_probs</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span> <span class="o">/</span> <span class="n">sm</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">sub_probs</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Prob_Regrowth&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpProbSpec</span><span class="p">(</span><span class="s1">&#39;Prob_Regrowth&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Prob_Regrowth&#39;</span><span class="p">),</span>
                                                  <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;tot_prob&#39;</span><span class="p">,</span> <span class="n">move_probs</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="p">(</span><span class="s1">&#39;sub_probs&#39;</span><span class="p">,</span> <span class="n">sub_probs</span><span class="p">)]),</span>
                                                  <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">})</span>
        <span class="n">max_ang</span> <span class="o">=</span> <span class="p">[</span><span class="mi">180</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_spec</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">:</span>
            <span class="n">max_ang</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">props</span><span class="p">[</span><span class="s1">&#39;Prob_Rotation&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">InpProbSpec</span><span class="p">(</span><span class="s1">&#39;Prob_Rotation&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;Prob_Rotation&#39;</span><span class="p">),</span>
                                                  <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;tot_prob&#39;</span><span class="p">,</span> <span class="n">move_probs</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span> <span class="p">(</span><span class="s1">&#39;limit_vals&#39;</span><span class="p">,</span> <span class="n">max_ang</span><span class="p">)]),</span>
                                                  <span class="o">**</span><span class="p">{</span><span class="s1">&#39;new_line&#39;</span><span class="p">:</span> <span class="bp">True</span><span class="p">,</span> <span class="s1">&#39;indicator&#39;</span><span class="p">:</span> <span class="s1">&#39;end&#39;</span><span class="p">})</span></div>


<div class="viewcode-block" id="InpSpec"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.InpSpec">[docs]</a><span class="k">class</span> <span class="nc">InpSpec</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.cassandra.InpSpec</span>

<span class="sd">     Represents the most common object used for carrying one logical unit of the CASSANDRA simulation options</span>

<span class="sd">     Parameters:</span>
<span class="sd">         key (str) : the keyword of the simulation option (literally the string that goes after the # sign in</span>
<span class="sd">            CASSANDRA .inp file)</span>
<span class="sd">         value (object) : numerical or text values of the particular simulation option structured in a certain way.</span>
<span class="sd">            Here goes only the values that are wished to be changed (it might be just one field of a big dictionary)</span>
<span class="sd">         default (object) : the most complete default description of the simulation option</span>

<span class="sd">     Keyword Args:</span>
<span class="sd">         write_headers (boolean): if the :obj:`~value` is dictionary defines whether the dictionary keys should be</span>
<span class="sd">            written to the output</span>
<span class="sd">         new_line (boolean): if the :obj:`~value` is iterable defines whether each new element will be written to</span>
<span class="sd">            the new line</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">default</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">key</span> <span class="o">=</span> <span class="n">key</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">write_headers</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;write_headers&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">is_new_line</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;new_line&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">value</span>
        <span class="k">if</span> <span class="n">value</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">default</span><span class="p">,</span> <span class="n">types</span><span class="o">.</span><span class="n">DictType</span><span class="p">):</span>
                <span class="c1"># Add from default structure all properties that were not defined by user</span>
                <span class="k">for</span> <span class="n">ky</span> <span class="ow">in</span> <span class="n">value</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                    <span class="n">default</span><span class="p">[</span><span class="n">ky</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="n">ky</span><span class="p">]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">default</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">value</span>
        <span class="k">elif</span> <span class="n">value</span> <span class="o">==</span> <span class="p">[]:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># If nothing was passed write default</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">default</span>

<div class="viewcode-block" id="InpSpec.to_string"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.InpSpec.to_string">[docs]</a>    <span class="k">def</span> <span class="nf">to_string</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.InpSpec.to_string</span>

<span class="sd">        Creates the proper text representation of the property stored in the :obj:`~value` field</span>

<span class="sd">        Returns:</span>
<span class="sd">            str:</span>
<span class="sd">                formatted text string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">result</span> <span class="o">=</span> <span class="s1">&#39;# {:}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">key</span><span class="p">)</span>
            <span class="c1"># Strings</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="n">types</span><span class="o">.</span><span class="n">StringTypes</span><span class="p">):</span>
                <span class="n">result</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
            <span class="c1"># Dictionaries</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="n">types</span><span class="o">.</span><span class="n">DictType</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">ks</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">write_headers</span><span class="p">:</span>
                        <span class="n">result</span> <span class="o">+=</span> <span class="n">ks</span> <span class="o">+</span> <span class="s1">&#39;  &#39;</span>

                    <span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">[</span><span class="n">ks</span><span class="p">]</span>
                    <span class="k">if</span> <span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="n">Iterable</span><span class="p">))</span> <span class="o">&amp;</span> <span class="p">(</span><span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="n">types</span><span class="o">.</span><span class="n">StringTypes</span><span class="p">)):</span>
                        <span class="n">result</span> <span class="o">+=</span> <span class="s1">&#39;   &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">tmp</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">result</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>

                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_new_line</span><span class="p">:</span>
                        <span class="n">result</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">result</span> <span class="o">+=</span> <span class="s1">&#39; &#39;</span>
                <span class="n">result</span> <span class="o">=</span> <span class="n">result</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>  <span class="c1"># Remove the very last new line character</span>
            <span class="c1"># Lists</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="n">Iterable</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">elem</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">:</span>
                    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">elem</span><span class="p">,</span> <span class="n">Iterable</span><span class="p">):</span>
                        <span class="n">subresult</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
                        <span class="k">for</span> <span class="n">subelem</span> <span class="ow">in</span> <span class="n">elem</span><span class="p">:</span>
                            <span class="n">subresult</span> <span class="o">=</span> <span class="n">subresult</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">subelem</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39; &#39;</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">subresult</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">elem</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39; &#39;</span>
                    <span class="n">result</span> <span class="o">+=</span> <span class="n">subresult</span>
            <span class="c1"># Simple types</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">result</span> <span class="o">+=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
            <span class="n">result</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">!{:^^20}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">result</span></div></div>


<div class="viewcode-block" id="InpProbSpec"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.InpProbSpec">[docs]</a><span class="k">class</span> <span class="nc">InpProbSpec</span><span class="p">(</span><span class="n">InpSpec</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.cassandra.InpSpec</span>

<span class="sd">    Extension of the :class:`~InpSpec` class that takes into account special representation of the movement</span>
<span class="sd">    probabilities in the CASSANDRA input file.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">default</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">InpProbSpec</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">default</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

<div class="viewcode-block" id="InpProbSpec.to_string"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.InpProbSpec.to_string">[docs]</a>    <span class="k">def</span> <span class="nf">to_string</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">tmp</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">InpProbSpec</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">to_string</span><span class="p">()</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s1">&#39;Prob_Translation&#39;</span><span class="p">:</span>
            <span class="n">tmp</span> <span class="o">=</span> <span class="s1">&#39;# Move_Probability_Info</span><span class="se">\n\n</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="n">tmp</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s1">&#39;Prob_Rotation&#39;</span><span class="p">:</span>
            <span class="n">tmp</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1"># Done_Probability_Info</span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="k">return</span> <span class="n">tmp</span></div></div>


<div class="viewcode-block" id="McSystem"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.McSystem">[docs]</a><span class="k">class</span> <span class="nc">McSystem</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.cassandra.McSystem</span>

<span class="sd">    Wrapper around the list of :class:`~pysimm.system.System` objects. Each element in the list represents single</span>
<span class="sd">    molecule of a different specie that will be used during MC simulations. Additionally, the object is responsible for</span>
<span class="sd">    creating .dat and .mcf files needed for the simulation and reading back the CASSANDRA simulation results.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        sst (list of :class:`~pysimm.system.System`) : items representing single molecules of different species to be</span>
<span class="sd">            inserted by CASSANDRA. If the sst is a list (not a single value) it is assumed that all of the following</span>
<span class="sd">            properties are synchronized with it by indexes.</span>
<span class="sd">        chem_pot (list of int) : chemical potential for each specie [Joule/mol]</span>

<span class="sd">    Keyword Args:</span>
<span class="sd">        max_ins (list of int) : defines the highest possible number of molecules of corresponding specie.</span>
<span class="sd">            Basing on these values CASSANDRA allocates memory for simulations. (default: 5000).</span>
<span class="sd">        is_rigid (list of boolean): defines whether the atoms in the particular molecule should be marked as rigid</span>
<span class="sd">            or not. **Important!** In current implementation the module doesn&#39;t support flexible molecule angles, so</span>
<span class="sd">            the `is_rigid=False` is designed to be used exclusively for **single bead** molecules.</span>

<span class="sd">    Parameters:</span>
<span class="sd">        made_ins (list of int) : number of particles of each specie inserted by CASSANDRA.</span>
<span class="sd">        mcf_file (list of str) : defines full relative names of molecule configuration files **(.mcf)** required by</span>
<span class="sd">            CASSANDRA. Files will be created automatically.</span>
<span class="sd">        frag_file (list of str) : defines full relative names of possible relative configuration files **(.dat)**</span>
<span class="sd">            required by CASSANDRA. Files will be created automatically.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sst</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">&#39;MC_SYSTEM&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sst</span> <span class="o">=</span> <span class="n">make_iterable</span><span class="p">(</span><span class="n">sst</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">sst</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sst</span><span class="p">:</span>
            <span class="n">sst</span><span class="o">.</span><span class="n">zero_charge</span><span class="p">()</span>
            <span class="c1"># Checking that the force-field of the input system is of the class-1 as it is direct CASSANDRA restriction</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">sst</span><span class="p">,</span> <span class="n">system</span><span class="o">.</span><span class="n">System</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">sst</span><span class="o">.</span><span class="n">ff_class</span><span class="p">:</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">sst</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">==</span> <span class="s1">&#39;1&#39;</span><span class="p">):</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Currently cassandra supports only with **Type-I** force fields. &#39;</span>
                                          <span class="s1">&#39;The PYSIMM systems you provided are of the different types&#39;</span>
                                          <span class="s1">&#39;Exiting...&#39;</span><span class="p">)</span>
                        <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;The Force-Field type of the system is not defined. &#39;</span>
                                     <span class="s1">&#39;Assuming it is **Type-1** force field&#39;</span><span class="p">)</span>

                    <span class="n">sst</span><span class="o">.</span><span class="n">ff_class</span> <span class="o">=</span> <span class="s1">&#39;1&#39;</span>
            <span class="c1"># Decorating the system with bonds_fixed flag and angle_fixed flag</span>
            <span class="k">for</span> <span class="n">bt</span> <span class="ow">in</span> <span class="n">sst</span><span class="o">.</span><span class="n">bond_types</span><span class="p">:</span>
                <span class="n">bt</span><span class="o">.</span><span class="n">is_fixed</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="n">sst</span><span class="o">.</span><span class="n">angle_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">at</span><span class="o">.</span><span class="n">k</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">at</span><span class="o">.</span><span class="n">is_fixed</span> <span class="o">=</span> <span class="bp">True</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">file_store</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">max_ins</span> <span class="o">=</span> <span class="n">make_iterable</span><span class="p">(</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;max_ins&#39;</span><span class="p">,</span> <span class="mi">5000</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">is_rigid</span> <span class="o">=</span> <span class="n">make_iterable</span><span class="p">(</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;is_rigid&#39;</span><span class="p">,</span> <span class="p">[</span><span class="bp">True</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sst</span><span class="p">)))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">made_ins</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sst</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mcf_file</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">frag_file</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">temperature</span> <span class="o">=</span> <span class="bp">None</span>

<div class="viewcode-block" id="McSystem.update_props"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.McSystem.update_props">[docs]</a>    <span class="k">def</span> <span class="nf">update_props</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">props</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.McSystem.update_props</span>

<span class="sd">        For each specie in the system creates the .mcf file required for CASSANDRA simulation.</span>

<span class="sd">        Args:</span>
<span class="sd">            props (dictionary) : contains the .mcf file names and maximally allowed number of molecules insertions.</span>
<span class="sd">                The dictionary is to be assigned to &#39;Molecule_Files&#39; property of the MC simulation</span>

<span class="sd">        Returns:</span>
<span class="sd">            props: updated input dictionary</span>
<span class="sd">       &quot;&quot;&quot;</span>
        <span class="c1"># Generate correct .mcf files</span>
        <span class="n">al_ind</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="p">(</span><span class="n">sstm</span><span class="p">,</span> <span class="n">count</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sst</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sst</span><span class="p">))):</span>
            <span class="n">fullfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">file_store</span><span class="p">,</span> <span class="s1">&#39;{:}{:}{:}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;particle&#39;</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">count</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="s1">&#39;.mcf&#39;</span><span class="p">))</span>
            <span class="k">for</span> <span class="n">p_type</span> <span class="ow">in</span> <span class="n">sstm</span><span class="o">.</span><span class="n">particle_types</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">p_type</span><span class="o">.</span><span class="n">elem</span> <span class="ow">and</span> <span class="p">(</span><span class="ow">not</span> <span class="n">p_type</span><span class="o">.</span><span class="n">real_elem</span><span class="p">):</span>
                    <span class="n">p_type</span><span class="o">.</span><span class="n">real_elem</span> <span class="o">=</span> <span class="n">p_type</span><span class="o">.</span><span class="n">elem</span>
                <span class="n">p_type</span><span class="o">.</span><span class="n">elem</span> <span class="o">=</span> <span class="n">ascii_uppercase</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">al_ind</span> <span class="o">/</span> <span class="mi">10</span><span class="p">)]</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">al_ind</span> <span class="o">%</span> <span class="mi">10</span><span class="p">)</span>
                <span class="n">al_ind</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">McfWriter</span><span class="p">(</span><span class="n">sstm</span><span class="p">,</span> <span class="n">fullfile</span><span class="p">)</span><span class="o">.</span><span class="n">write</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mcf_file</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fullfile</span><span class="p">)</span>
        <span class="c1"># Make the files list to be returned</span>
        <span class="n">offset</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">props</span><span class="p">)</span>
        <span class="k">for</span> <span class="p">(</span><span class="n">mcf</span><span class="p">,</span> <span class="n">ins</span><span class="p">,</span> <span class="n">count</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mcf_file</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_ins</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">offset</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mcf_file</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">offset</span><span class="p">)):</span>
            <span class="n">props</span><span class="p">[</span><span class="s1">&#39;file&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">count</span><span class="p">)]</span> <span class="o">=</span> <span class="p">[</span><span class="n">mcf</span><span class="p">,</span> <span class="n">ins</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">props</span></div>

<div class="viewcode-block" id="McSystem.update_frag_record"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.McSystem.update_frag_record">[docs]</a>    <span class="k">def</span> <span class="nf">update_frag_record</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">frag_record</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.McSystem.update_frag_record</span>

<span class="sd">        For each specie in the system creates the single configuration .dat file required for CASSANDRA simulation.</span>

<span class="sd">        Args:</span>
<span class="sd">            frag_record: dictionary containing the .dat file names and their ids. The dictionary is to be assigned to</span>
<span class="sd">            &#39;Molecule_Files&#39; property of the MC simulation</span>

<span class="sd">        Returns:</span>
<span class="sd">            dictionary:</span>
<span class="sd">                updated dictionary</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Generating the structure files</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">temperature</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">temperature</span> <span class="o">=</span> <span class="mi">300</span>

        <span class="k">for</span> <span class="p">(</span><span class="n">sstm</span><span class="p">,</span> <span class="n">count</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sst</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sst</span><span class="p">))):</span>
            <span class="n">fullfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">file_store</span><span class="p">,</span> <span class="s1">&#39;{:}{:}{:}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;particle&#39;</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">count</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="s1">&#39;.dat&#39;</span><span class="p">))</span>
            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fullfile</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">out</span><span class="p">:</span>
                <span class="n">frag_count</span> <span class="o">=</span> <span class="mi">1</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:&gt;12d}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">frag_count</span><span class="p">))</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:&gt;21f}{:&gt;21f}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">temperature</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
                <span class="n">tmplte</span> <span class="o">=</span> <span class="s1">&#39;{:&lt;10}{:&lt;24f}{:&lt;24f}{:&lt;24f}</span><span class="se">\n</span><span class="s1">&#39;</span>
                <span class="k">for</span> <span class="n">prt</span> <span class="ow">in</span> <span class="n">sstm</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                    <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">tmplte</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">prt</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">prt</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">prt</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">prt</span><span class="o">.</span><span class="n">z</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">frag_file</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fullfile</span><span class="p">)</span>
        <span class="c1"># Generating the files list</span>
        <span class="k">for</span> <span class="p">(</span><span class="n">frags</span><span class="p">,</span> <span class="n">count</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">frag_file</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">frag_file</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)):</span>
            <span class="n">frag_record</span><span class="p">[</span><span class="s1">&#39;file&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">count</span><span class="p">)]</span> <span class="o">=</span> <span class="p">[</span><span class="n">frags</span><span class="p">,</span> <span class="n">count</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">frag_record</span></div>

<div class="viewcode-block" id="McSystem.make_system"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.McSystem.make_system">[docs]</a>    <span class="k">def</span> <span class="nf">make_system</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text_output</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.McSystem.make_system</span>

<span class="sd">        Parses the checkpoint (.chk) file made by CASSANDRA and creates new molecules basing on the new coordinates</span>
<span class="sd">        information. Assumes that all atoms of a certain molecule are listed in .chk file together (molecule</span>
<span class="sd">        identifiers are not mixed).</span>

<span class="sd">        Note:</span>
<span class="sd">            The logic of comparison of the xyz-like text record from the .chk file with the</span>
<span class="sd">            :class:`~pysimm.system.System` object is most straightforward: It is the consecutive comparison of particle</span>
<span class="sd">            names and first letters (before the white space) in the text record. In this implementation order matters!</span>
<span class="sd">            For example, for CO2, if in the system atoms are ordered as C-O-O and in the text they are ordered as</span>
<span class="sd">            O-C-O fit will fail.</span>

<span class="sd">        Args:</span>
<span class="sd">            text_output (str): text stream from the CASSANDRA .chk file containing the coordinates of newly inserted</span>
<span class="sd">                molecules</span>

<span class="sd">        Returns:</span>
<span class="sd">            :class:`~pysimm.system.System` : object containing all newly inserted molecules</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">sstm</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>  <span class="c1"># counter of the lines in the input file</span>
        <span class="n">sys_idx</span> <span class="o">=</span> <span class="mi">0</span>  <span class="c1"># counter of the gas molecules to lookup</span>
        <span class="k">while</span> <span class="n">count</span> <span class="o">&lt;</span> <span class="nb">len</span><span class="p">(</span><span class="n">text_output</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">tmp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sst</span><span class="p">[</span><span class="n">sys_idx</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="n">dictn</span> <span class="o">=</span> <span class="n">text_output</span><span class="p">[</span><span class="n">count</span><span class="p">:(</span><span class="nb">len</span><span class="p">(</span><span class="n">tmp</span><span class="o">.</span><span class="n">particles</span><span class="p">)</span> <span class="o">+</span> <span class="n">count</span><span class="p">)]</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__fit_atoms__</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="n">dictn</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">tmp</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                    <span class="n">vals</span> <span class="o">=</span> <span class="n">dictn</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">tag</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                    <span class="c1"># Read the coordinates from the text output of the CASSANDRA simulation</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">z</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="n">vals</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">4</span><span class="p">])</span>
                    <span class="c1"># Force velocities of the particles to be 0</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">vx</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">vy</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">vz</span> <span class="o">=</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span>
                    <span class="n">p</span><span class="o">.</span><span class="n">molecule</span><span class="o">.</span><span class="n">syst_tag</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_rigid</span><span class="p">[</span><span class="n">sys_idx</span><span class="p">]:</span>
                    <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">tmp</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                        <span class="n">p</span><span class="o">.</span><span class="n">is_rigid</span> <span class="o">=</span> <span class="bp">True</span>
                <span class="k">if</span> <span class="n">sstm</span><span class="p">:</span>
                    <span class="n">sstm</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">sstm</span> <span class="o">=</span> <span class="n">tmp</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">made_ins</span><span class="p">[</span><span class="n">sys_idx</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
                <span class="n">count</span> <span class="o">+=</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp</span><span class="o">.</span><span class="n">particles</span><span class="p">)</span>
                <span class="n">sys_idx</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">sys_idx</span> <span class="o">+=</span> <span class="mi">1</span>
                <span class="k">if</span> <span class="n">sys_idx</span> <span class="o">&gt;=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sst</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Wasn</span><span class="se">\&#39;</span><span class="s1">t able to read CASSANDRA .chk file. &#39;</span>
                                      <span class="s1">&#39;Please check either MC-simulation provided to PySIMM or the CASSANDRA &#39;</span>
                                      <span class="s1">&#39;checkpoint file &#39;</span><span class="p">)</span>
                    <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">sstm</span><span class="o">.</span><span class="n">update_tags</span><span class="p">()</span>
        <span class="n">sstm</span><span class="o">.</span><span class="n">objectify</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">sstm</span></div>

    <span class="k">def</span> <span class="nf">__fit_atoms__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">molec</span><span class="p">,</span> <span class="n">text_lines</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.McSystem.__fit_atoms__</span>

<span class="sd">        Implements simple logic of comparison of the xyz-like text record with the :class:`~pysimm.system.System`</span>
<span class="sd">        object. The comparison is based on the consecutive comparison of particle names and first letters (before the</span>
<span class="sd">        white space) in the text. In this implementation order matters!  E.g. for CO2, if in the system atoms are</span>
<span class="sd">        ordered as C-O-O and in the text they are ordered like O-C-O fit will return False.</span>

<span class="sd">        Returns:</span>
<span class="sd">            boolean: flag whether the text record fit the molecule or not</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">flag</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="c1"># Cannot map anything if number of molecules is different from number of data lines</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">molec</span><span class="o">.</span><span class="n">particles</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">text_lines</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">False</span>
        <span class="c1"># Check the sequence of element names they</span>
        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">molec</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="n">vals</span> <span class="o">=</span> <span class="n">text_lines</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">tag</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>

            <span class="k">if</span> <span class="n">vals</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="n">p</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span><span class="p">:</span>
                <span class="k">return</span> <span class="bp">False</span>
        <span class="k">return</span> <span class="n">flag</span></div>


<div class="viewcode-block" id="Cassandra"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.Cassandra">[docs]</a><span class="k">class</span> <span class="nc">Cassandra</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.cassandra.Cassandra</span>

<span class="sd">    Organizational object for running CASSANDRA simulation tasks. In current implementation it is able to run Canonical,</span>
<span class="sd">    Grand Canonical, and Isothermal-Isobaric Monte Carlo simulations (:class:`~GCMC`, :class:`~NVT`, and :class:`~NPT`,</span>
<span class="sd">    correspondingly).</span>

<span class="sd">    Parameters:</span>
<span class="sd">        system (:class:`~pysimm.system.System`) : molecular updated during the simulations</span>
<span class="sd">        run_queue (list) : the list of scheduled tasks</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">init_sst</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">&#39;CSNDRA&#39;</span><span class="p">)</span>

        <span class="c1"># Assume all particles in initial sysrem are fixed</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">system</span> <span class="o">=</span> <span class="n">init_sst</span>
        <span class="k">if</span> <span class="n">init_sst</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">init_sst</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                <span class="n">p</span><span class="o">.</span><span class="n">is_fixed</span> <span class="o">=</span> <span class="bp">True</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">run_queue</span> <span class="o">=</span> <span class="p">[]</span>

<div class="viewcode-block" id="Cassandra.run"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.Cassandra.run">[docs]</a>    <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.Cassandra.run</span>

<span class="sd">        Method that triggers the simulations. Does two consecutive steps: **(1)** tries to write all files necessary</span>
<span class="sd">        for simulation (.dat, .inp, .mcf): **(2)** tries to invoke the CASSANDRA executable.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">global</span> <span class="n">CASSANDRA_EXEC</span>

        <span class="k">if</span> <span class="n">check_cs_exec</span><span class="p">():</span>
            <span class="k">for</span> <span class="n">task</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">run_queue</span><span class="p">:</span>
                <span class="c1"># Write .inp file</span>
                <span class="n">task</span><span class="o">.</span><span class="n">write</span><span class="p">()</span>
                <span class="c1"># Write .xyz of the fixed system if provided</span>
                <span class="k">if</span> <span class="n">task</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">task</span><span class="o">.</span><span class="n">fxd_sst_mcfile</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                        <span class="n">McfWriter</span><span class="p">(</span><span class="n">task</span><span class="o">.</span><span class="n">fxd_sst</span><span class="p">,</span> <span class="n">task</span><span class="o">.</span><span class="n">fxd_sst_mcfile</span><span class="p">)</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;atoms&#39;</span><span class="p">)</span>
                    <span class="n">task</span><span class="o">.</span><span class="n">fxd_sst</span><span class="o">.</span><span class="n">write_xyz</span><span class="p">(</span><span class="n">task</span><span class="o">.</span><span class="n">fxd_sst_xyz</span><span class="p">)</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Starting the GCMC simulations with CASSANDRA&#39;</span><span class="p">)</span>
                    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;{:.^60}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">))</span>
                    <span class="n">call</span><span class="p">([</span><span class="n">CASSANDRA_EXEC</span><span class="p">,</span> <span class="n">task</span><span class="o">.</span><span class="n">props_file</span><span class="p">])</span>
                    <span class="n">task</span><span class="o">.</span><span class="n">upd_simulation</span><span class="p">()</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">system</span> <span class="o">=</span> <span class="n">task</span><span class="o">.</span><span class="n">tot_sst</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>

                <span class="k">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">ose</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;There was a problem calling CASSANDRA executable&#39;</span><span class="p">)</span>
                    <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
                <span class="k">except</span> <span class="ne">IOError</span> <span class="k">as</span> <span class="n">ioe</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">check_cs_exec</span><span class="p">():</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;There was a problem running CASSANDRA. The process started but did not finish&#39;</span><span class="p">)</span>
                        <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;There was a problem running CASSANDRA: seems it is not configured properly.</span><span class="se">\n</span><span class="s1">&#39;</span>
                              <span class="s1">&#39;Please, be sure the CSNDRA_EXEC environment variable is set to the correct &#39;</span>
                              <span class="s1">&#39;CASSANDRA executable path. The current path is set to:</span><span class="se">\n\n</span><span class="s1">{}</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">CASSANDRA_EXEC</span><span class="p">))</span>
            <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span></div>

<div class="viewcode-block" id="Cassandra.add_simulation"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.Cassandra.add_simulation">[docs]</a>    <span class="k">def</span> <span class="nf">add_simulation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ens_type</span><span class="p">,</span> <span class="n">obj</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.Cassandra.add_simulation</span>

<span class="sd">        Method for adding new Monte Carlo simulation to the run queue.</span>

<span class="sd">        Args:</span>
<span class="sd">            ens_type: Type of the molecular ensemble for the Monte-Carlo simulations. The supported options are: `GCMC`</span>
<span class="sd">                (Grand Canonical); `NVT` (canonical); `NPT` (isobaric-isothermal)</span>
<span class="sd">            obj: the entity that should be added. Will be ignored if it is not of a type  :class:`~MCSimulation`</span>

<span class="sd">        Keyword Args:</span>
<span class="sd">            is_new (boolean) : defines whether all previous simulations should be erased or not</span>
<span class="sd">            species (list of :class:`~pysimm.system.System`) : systems that describe molecules and will be passed to</span>
<span class="sd">                :class:`~McSystem` constructor.</span>

<span class="sd">        Note:</span>
<span class="sd">            Other keyword arguments of this method will be redirected to the :class:`~McSystem` and</span>
<span class="sd">            :class:`~MCSimulation` constructors. See their descriptions for the possible keyword options.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">new_job</span> <span class="o">=</span> <span class="bp">None</span>

        <span class="c1"># Reading the molecule ensemble type</span>
        <span class="n">simul</span> <span class="o">=</span> <span class="n">locate</span><span class="p">(</span><span class="s1">&#39;pysimm.cassandra.&#39;</span> <span class="o">+</span> <span class="n">ens_type</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">simul</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Unsopported simulation ensemble option. Please use ether GCMC, NPT, or &#39;</span>
                              <span class="s1">&#39;NVT in </span><span class="se">\&#39;</span><span class="s1">add_simulation</span><span class="se">\&#39;</span><span class="s1"> &#39;</span><span class="p">)</span>
            <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">MCSimulation</span><span class="p">):</span>
            <span class="n">new_job</span> <span class="o">=</span> <span class="n">obj</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">specs</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;species&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">specs</span><span class="p">:</span>
                <span class="n">mc_sst</span> <span class="o">=</span> <span class="n">McSystem</span><span class="p">(</span><span class="n">specs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
                <span class="n">new_job</span> <span class="o">=</span> <span class="n">simul</span><span class="p">(</span><span class="n">mc_sst</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">system</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Incorrect &#39;</span> <span class="o">+</span> <span class="n">ens_type</span> <span class="o">+</span> <span class="s1">&#39; initialization. Please provide either Cassandra.&#39;</span> <span class="o">+</span>
                                  <span class="n">ens_type</span> <span class="o">+</span> <span class="s1">&#39; simulation object or the dictionary with initialization parameters &#39;</span>
                                  <span class="s1">&#39;of that object&#39;</span><span class="p">)</span>
                <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="c1"># Clean the run queue if &#39;is_new&#39; set to to True</span>
        <span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;is_new&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">run_queue</span><span class="p">[:]</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="n">new_job</span><span class="p">:</span>
            <span class="n">new_job</span><span class="o">.</span><span class="n">__check_params__</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">run_queue</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_job</span><span class="p">)</span></div>

<div class="viewcode-block" id="Cassandra.add_gcmc"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.Cassandra.add_gcmc">[docs]</a>    <span class="k">def</span> <span class="nf">add_gcmc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.Cassandra.add_gcmc</span>

<span class="sd">        Ads new simulation in grand-canonical ensemble to the run queue.</span>

<span class="sd">        Args:</span>
<span class="sd">            obj: the entity that should be added. Will be ignored if it is not of a type  :class:`~GCMC`</span>

<span class="sd">        Keyword Args:</span>
<span class="sd">            is_new (boolean) : defines whether all previous simulations should be erased or not</span>
<span class="sd">            species (list of :class:`~pysimm.system.System`) : systems that describe molecules and will be passed to</span>
<span class="sd">                :class:`~McSystem` constructor.</span>

<span class="sd">        Note:</span>
<span class="sd">            Other keyword arguments of this method will be redirected to the :class:`~McSystem`, :class:`~MCSimulation`,</span>
<span class="sd">             and :class:`~GCMC` constructors. See their descriptions for the possible keyword options.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">new_job</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">GCMC</span><span class="p">):</span>
            <span class="n">new_job</span> <span class="o">=</span> <span class="n">obj</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">specs</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;species&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">specs</span><span class="p">:</span>
                <span class="n">mc_sst</span> <span class="o">=</span> <span class="n">McSystem</span><span class="p">(</span><span class="n">specs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
                <span class="n">new_job</span> <span class="o">=</span> <span class="n">GCMC</span><span class="p">(</span><span class="n">mc_sst</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">system</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Unknown GCMC initialization. Please provide either &#39;</span>
                                  <span class="s1">&#39;the dictionary with GCMC parameters or Cassandra.GCMC simulation object&#39;</span><span class="p">)</span>
                <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;is_new&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">run_queue</span><span class="p">[:]</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="n">new_job</span><span class="p">:</span>
            <span class="n">new_job</span><span class="o">.</span><span class="n">__check_params__</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">run_queue</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_job</span><span class="p">)</span></div>

<div class="viewcode-block" id="Cassandra.add_npt_mc"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.Cassandra.add_npt_mc">[docs]</a>    <span class="k">def</span> <span class="nf">add_npt_mc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.Cassandra.add_npt_mc</span>

<span class="sd">        Ads new simulation in isobaric-isothermal ensemble to the run queue.</span>

<span class="sd">        Args:</span>
<span class="sd">            obj: the entity that should be added. Will be ignored if it is not of a type  :class:`~NPT`</span>

<span class="sd">        Keyword Args:</span>
<span class="sd">            is_new (boolean) : defines whether all previous simulations should be erased or not</span>
<span class="sd">            species (list of :class:`~pysimm.system.System`) : systems that describe molecules and will be passed to</span>
<span class="sd">                :class:`~McSystem` constructor.</span>

<span class="sd">        Note:</span>
<span class="sd">            Other keyword arguments of this method will be redirected to the :class:`~McSystem`, :class:`~MCSimulation`,</span>
<span class="sd">            and  :class:`~NPT` constructors. See their descriptions for the possible keyword options.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">new_job</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">NPT</span><span class="p">):</span>
            <span class="n">new_job</span> <span class="o">=</span> <span class="n">obj</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">specs</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;species&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">specs</span><span class="p">:</span>
                <span class="n">mc_sst</span> <span class="o">=</span> <span class="n">McSystem</span><span class="p">(</span><span class="n">specs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
                <span class="n">new_job</span> <span class="o">=</span> <span class="n">NPT</span><span class="p">(</span><span class="n">mc_sst</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">system</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Unknown NPT initialization. Please provide either &#39;</span>
                                  <span class="s1">&#39;the dictionary with NPT simulation parameters or Cassandra.NPT simulation object&#39;</span><span class="p">)</span>
                <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;is_new&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">run_queue</span><span class="p">[:]</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="n">new_job</span><span class="p">:</span>
            <span class="n">new_job</span><span class="o">.</span><span class="n">__check_params__</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">run_queue</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_job</span><span class="p">)</span></div>

<div class="viewcode-block" id="Cassandra.add_nvt"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.Cassandra.add_nvt">[docs]</a>    <span class="k">def</span> <span class="nf">add_nvt</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.Cassandra.add_nvt</span>

<span class="sd">        Ads new simulation in canonical ensemble to the run queue.</span>

<span class="sd">        Args:</span>
<span class="sd">            obj: the entity that should be added. Will be ignored if it is not of a type  :class:`~NVT`</span>

<span class="sd">        Keyword Args:</span>
<span class="sd">            is_new (boolean) : defines whether all previous simulations should be erased or not</span>
<span class="sd">            species (list of :class:`~pysimm.system.System`) : systems that describe molecules and will be passed to</span>
<span class="sd">                :class:`~McSystem` constructor.</span>

<span class="sd">        Note:</span>
<span class="sd">            Other keyword arguments of this method will be redirected to the :class:`~McSystem`, :class:`~MCSimulation`,</span>
<span class="sd">            and  :class:`~NVT` constructors. See their descriptions for the possible keyword options.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">new_job</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">NVT</span><span class="p">):</span>
            <span class="n">new_job</span> <span class="o">=</span> <span class="n">obj</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">specs</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;species&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">specs</span><span class="p">:</span>
                <span class="n">mc_sst</span> <span class="o">=</span> <span class="n">McSystem</span><span class="p">(</span><span class="n">specs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
                <span class="n">new_job</span> <span class="o">=</span> <span class="n">NVT</span><span class="p">(</span><span class="n">mc_sst</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">system</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Unknown NVT initialization. Please provide either &#39;</span>
                                  <span class="s1">&#39;the dictionary with NPT simulation parameters or Cassandra.NPT simulation object&#39;</span><span class="p">)</span>
                <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;is_new&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">run_queue</span><span class="p">[:]</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">if</span> <span class="n">new_job</span><span class="p">:</span>
            <span class="n">new_job</span><span class="o">.</span><span class="n">__check_params__</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">run_queue</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">new_job</span><span class="p">)</span></div>

<div class="viewcode-block" id="Cassandra.read_input"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.Cassandra.read_input">[docs]</a>    <span class="k">def</span> <span class="nf">read_input</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">inp_file</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.Cassandra.read_input</span>

<span class="sd">        The method parses the CASSANDRA instructions file (.inp) split it into separate instructions and analyses each</span>
<span class="sd">        according to the instruction name.</span>

<span class="sd">        Args:</span>
<span class="sd">            inp_file (str) : the full relative path of the file to be read</span>

<span class="sd">        Returns:</span>
<span class="sd">            dictionary : read CASSANDRA properties in the format required by :class:`~GCMC`</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">result</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">inp_file</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Reading simulation parameters from {:} file&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">inp_file</span><span class="p">))</span>
            <span class="c1"># Reading the cassandra .inp file as one long string</span>
            <span class="n">inp_stream</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">inp_file</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span>
            <span class="n">lines</span> <span class="o">=</span> <span class="n">inp_stream</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
            <span class="n">raw_props</span> <span class="o">=</span> <span class="n">lines</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;#&#39;</span><span class="p">)</span>

            <span class="k">for</span> <span class="n">prop</span> <span class="ow">in</span> <span class="n">raw_props</span><span class="p">:</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">!.*&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">prop</span><span class="p">)</span>  <span class="c1"># Get rid of the CASSANDRA comments</span>
                <span class="n">line</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">(e|E)(n|N)(d|D)&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>  <span class="c1"># Get rid of the &#39;END in the end of the file</span>
                <span class="n">tmp</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                    <span class="n">result</span><span class="p">[</span><span class="n">tmp</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__parse_value__</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>

            <span class="c1"># File seems fine let&#39;s close the stream and return true in the flag</span>
            <span class="n">inp_stream</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Reading finished sucsessfully&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Cannot find specified file: </span><span class="se">\&quot;</span><span class="s1">{:}</span><span class="se">\&quot;</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">inp_file</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">result</span></div>

    <span class="k">def</span> <span class="nf">__parse_value__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cells</span><span class="p">):</span>
        <span class="n">title</span> <span class="o">=</span> <span class="n">cells</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;run_type&#39;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;type&#39;</span><span class="p">,</span> <span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="p">(</span><span class="s1">&#39;steps&#39;</span><span class="p">,</span> <span class="nb">map</span><span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="n">cells</span><span class="p">[</span><span class="mi">2</span><span class="p">:]))])</span>

        <span class="k">elif</span> <span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;charge_style&#39;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;type&#39;</span><span class="p">,</span> <span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                <span class="p">(</span><span class="s1">&#39;sum_type&#39;</span><span class="p">,</span> <span class="n">cells</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                <span class="p">(</span><span class="s1">&#39;cut_val&#39;</span><span class="p">,</span> <span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">3</span><span class="p">])),</span>
                                <span class="p">(</span><span class="s1">&#39;accuracy&#39;</span><span class="p">,</span> <span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">4</span><span class="p">]))])</span>

        <span class="k">elif</span> <span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;vdw_style&#39;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;type&#39;</span><span class="p">,</span> <span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                                <span class="p">(</span><span class="s1">&#39;cut_type&#39;</span><span class="p">,</span> <span class="n">cells</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                <span class="p">(</span><span class="s1">&#39;cut_val&#39;</span><span class="p">,</span> <span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">3</span><span class="p">]))])</span>

        <span class="k">elif</span> <span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;simulation_length_info&#39;</span><span class="p">:</span>
            <span class="n">tmp</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;units&#39;</span><span class="p">,</span> <span class="n">cells</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                               <span class="p">(</span><span class="s1">&#39;prop_freq&#39;</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">4</span><span class="p">])),</span>
                               <span class="p">(</span><span class="s1">&#39;coord_freq&#39;</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">6</span><span class="p">])),</span>
                               <span class="p">(</span><span class="s1">&#39;run&#39;</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">8</span><span class="p">]))])</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">cells</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">10</span><span class="p">:</span>
                <span class="n">tmp</span><span class="p">[</span><span class="s1">&#39;steps_per_sweep&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">10</span><span class="p">])</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">cells</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">12</span><span class="p">:</span>
                    <span class="n">tmp</span><span class="p">[</span><span class="s1">&#39;block_averages&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">12</span><span class="p">])</span>
            <span class="k">return</span> <span class="n">tmp</span>

        <span class="k">elif</span> <span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;cbmc_info&#39;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;kappa_ins&#39;</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">2</span><span class="p">])),</span>
                                <span class="p">(</span><span class="s1">&#39;kappa_dih&#39;</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">4</span><span class="p">])),</span>
                                <span class="p">(</span><span class="s1">&#39;rcut_cbmc&#39;</span><span class="p">,</span> <span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">6</span><span class="p">]))])</span>

        <span class="k">elif</span> <span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;box_info&#39;</span><span class="p">:</span>
            <span class="n">size</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">cells</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">6</span><span class="p">:</span>
                <span class="n">size</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span> <span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">4</span><span class="p">]),</span> <span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">5</span><span class="p">])]</span>
            <span class="k">return</span> <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;box_count&#39;</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">])),</span> <span class="p">(</span><span class="s1">&#39;box_type&#39;</span><span class="p">,</span> <span class="n">cells</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="p">(</span><span class="s1">&#39;box_size&#39;</span><span class="p">,</span> <span class="n">size</span><span class="p">)])</span>

        <span class="k">elif</span> <span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;prob_translation&#39;</span><span class="p">:</span>
            <span class="n">vals</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cells</span><span class="p">)):</span>
                <span class="n">vals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
            <span class="k">return</span> <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;tot_prob&#39;</span><span class="p">,</span> <span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">])),</span>
                                <span class="p">(</span><span class="s1">&#39;limit_vals&#39;</span><span class="p">,</span> <span class="n">vals</span><span class="p">)])</span>

        <span class="k">elif</span> <span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;prob_insertion&#39;</span><span class="p">:</span>
            <span class="n">vals</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cells</span><span class="p">)):</span>
                <span class="n">vals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
            <span class="k">return</span> <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;tot_prob&#39;</span><span class="p">,</span> <span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">])),</span>
                                <span class="p">(</span><span class="s1">&#39;types&#39;</span><span class="p">,</span> <span class="n">vals</span><span class="p">)])</span>

        <span class="k">elif</span> <span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;prob_rotation&#39;</span><span class="p">:</span>
            <span class="n">vals</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cells</span><span class="p">)):</span>
                <span class="n">vals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
            <span class="k">return</span> <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;tot_prob&#39;</span><span class="p">,</span> <span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">])),</span>
                                <span class="p">(</span><span class="s1">&#39;limit_vals&#39;</span><span class="p">,</span> <span class="n">vals</span><span class="p">)])</span>

        <span class="k">elif</span> <span class="p">(</span><span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;molecule_files&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;fragment_files&#39;</span><span class="p">):</span>
            <span class="n">tmp</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">c</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cells</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">cells</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)):</span>
                <span class="n">tmp</span><span class="p">[</span><span class="s1">&#39;file&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="p">)]</span> <span class="o">=</span> <span class="p">[</span><span class="n">cells</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">])]</span>
            <span class="k">return</span> <span class="n">tmp</span>

        <span class="k">elif</span> <span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;start_type&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;read_config&#39;</span><span class="p">:</span>
                <span class="n">specs</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cells</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span>
                    <span class="n">specs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
                <span class="k">return</span> <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;start_type&#39;</span><span class="p">,</span> <span class="s1">&#39;read_config&#39;</span><span class="p">),</span>
                                    <span class="p">(</span><span class="s1">&#39;species&#39;</span><span class="p">,</span> <span class="n">specs</span><span class="p">),</span>
                                    <span class="p">(</span><span class="s1">&#39;file_name&#39;</span><span class="p">,</span> <span class="n">cells</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])])</span>

            <span class="k">if</span> <span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;make_config&#39;</span><span class="p">:</span>
                <span class="n">specs</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cells</span><span class="p">)):</span>
                    <span class="n">specs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
                <span class="k">return</span> <span class="n">OrderedDict</span><span class="p">([(</span><span class="s1">&#39;start_type&#39;</span><span class="p">,</span> <span class="s1">&#39;make_config&#39;</span><span class="p">),</span>
                                    <span class="p">(</span><span class="s1">&#39;species&#39;</span><span class="p">,</span> <span class="n">specs</span><span class="p">),</span>
                                    <span class="p">(</span><span class="s1">&#39;file_name&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)])</span>
            <span class="k">if</span> <span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;add to config&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Sorry, </span><span class="se">\&#39;</span><span class="s1">add to config</span><span class="se">\&#39;</span><span class="s1"> regime  of &#39;&#39;Start_Type option is not supported yet&#39;</span><span class="p">)</span>
                <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;checkpoint&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Sorry, </span><span class="se">\&#39;</span><span class="s1">checkpoint</span><span class="se">\&#39;</span><span class="s1"> regime  of &#39;&#39;Start_Type option is not supported yet &#39;</span><span class="p">)</span>
                <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

        <span class="k">elif</span> <span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;property_info&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">tmp</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">cells</span><span class="p">)):</span>
                    <span class="n">tmp</span><span class="p">[</span><span class="s1">&#39;prop&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)]</span> <span class="o">=</span> <span class="nb">str</span><span class="o">.</span><span class="n">lower</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                <span class="k">return</span> <span class="n">tmp</span>

        <span class="k">elif</span> <span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;seed_info&#39;</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">2</span><span class="p">])]</span>

        <span class="k">elif</span> <span class="p">(</span><span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;prob_deletion&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;rcutoff_low&#39;</span><span class="p">)</span> <span class="ow">or</span> \
             <span class="p">(</span><span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;bond_prob_cutoff&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;chemical_potential_info&#39;</span><span class="p">):</span>
            <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>

        <span class="k">elif</span> <span class="p">(</span><span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;average_Info&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;nbr_species&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;temperature_info&#39;</span><span class="p">):</span>
            <span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">cells</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></div>


<div class="viewcode-block" id="McfWriter"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.McfWriter">[docs]</a><span class="k">class</span> <span class="nc">McfWriter</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.cassandra.McfWriter</span>

<span class="sd">    Object responsible for creating the CASSANDRA Molecular Configuration file (.mcf).</span>

<span class="sd">    Attributes:</span>
<span class="sd">        syst (:class:`~pysimm.system.System`) :represents the molecule to be described</span>
<span class="sd">        file_ref (str) : full relative path to the file that will be created</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Section names in any .mcf file</span>
    <span class="n">mcf_tags</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;# Atom_Info&#39;</span><span class="p">,</span> <span class="s1">&#39;# Bond_Info&#39;</span><span class="p">,</span> <span class="s1">&#39;# Angle_Info&#39;</span><span class="p">,</span> <span class="s1">&#39;# Dihedral_Info&#39;</span><span class="p">,</span>
                <span class="s1">&#39;# Improper_Info&#39;</span><span class="p">,</span> <span class="s1">&#39;# Intra_Scaling&#39;</span><span class="p">,</span> <span class="s1">&#39;# Fragment_Info&#39;</span><span class="p">,</span> <span class="s1">&#39;# Fragment_Connectivity&#39;</span><span class="p">]</span>
    <span class="n">empty_line</span> <span class="o">=</span> <span class="s1">&#39;0&#39;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">syst</span><span class="p">,</span> <span class="n">file_ref</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">syst</span> <span class="o">=</span> <span class="n">syst</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">file_ref</span> <span class="o">=</span> <span class="n">file_ref</span>

<div class="viewcode-block" id="McfWriter.write"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.McfWriter.write">[docs]</a>    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">typing</span><span class="o">=</span><span class="s1">&#39;all&#39;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;pysimm.cassandra.McfWriter.write</span>

<span class="sd">        Method creates the .mcf file writing only those sections of it that are marked to be written</span>

<span class="sd">        Args:</span>
<span class="sd">            typing (list) : the list of sections to be written or the text keyword. List items should be as they are</span>
<span class="sd">                defined in :class:`~pysimm.cassandra.McfWriter.mcf_tags` field); default &#39;all&#39;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Initializing output stream</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">file_ref</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">out_stream</span><span class="p">:</span>
            <span class="k">for</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">is_write</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mcf_tags</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">__to_tags__</span><span class="p">(</span><span class="n">typing</span><span class="p">)):</span>
                <span class="k">if</span> <span class="n">is_write</span><span class="p">:</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="n">method</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s1">&#39;__write_&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="o">.</span><span class="n">lower</span><span class="p">(</span><span class="n">name</span><span class="p">[</span><span class="mi">2</span><span class="p">:])</span> <span class="o">+</span> <span class="s1">&#39;__&#39;</span><span class="p">)</span>
                        <span class="n">method</span><span class="p">(</span><span class="n">out_stream</span><span class="p">)</span>
                    <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">__write_empty__</span><span class="p">(</span><span class="n">out_stream</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">__write_empty__</span><span class="p">(</span><span class="n">out_stream</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
            <span class="n">out_stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">END&#39;</span><span class="p">)</span>
            <span class="n">out_stream</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>

    <span class="k">def</span> <span class="nf">__write_empty__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">out</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{0:}</span><span class="se">\n</span><span class="s1">{1:}</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">empty_line</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">__write_atom_info__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">out</span><span class="p">):</span>
        <span class="k">global</span> <span class="n">KCALMOL_2_K</span>
        <span class="n">text_tag</span> <span class="o">=</span> <span class="s1">&#39;# Atom_Info&#39;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">syst</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="c1"># writing section header</span>
            <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">text_tag</span><span class="p">))</span>
            <span class="c1"># Verify and fix net system charge</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">syst</span><span class="o">.</span><span class="n">zero_charge</span><span class="p">()</span>
            <span class="c1"># writing total number of particles</span>
            <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{0:&lt;6}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">syst</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">))</span>
            <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">line_template</span> <span class="o">=</span> <span class="s1">&#39;{l[0]:&lt;6}{l[1]:&lt;7}{l[2]:&lt;5}{l[3]:&lt;8.3f}{l[4]:&lt;10.6f}&#39;</span> \
                            <span class="s1">&#39;{l[5]:&lt;6}{l[6]:&lt;11.3f}{l[7]:&lt;9.3f}</span><span class="se">\n</span><span class="s1">&#39;</span>
            <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">syst</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
                <span class="n">line</span> <span class="o">=</span> <span class="p">[</span><span class="n">count</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;LJ&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span>
                <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="s1">&#39;charge&#39;</span><span class="p">):</span>
                    <span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">charge</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">line</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="s1">&#39;type&#39;</span><span class="p">):</span>
                    <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">):</span>
                        <span class="n">line</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">name</span>
                    <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="s1">&#39;elem&#39;</span><span class="p">):</span>
                        <span class="n">line</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">elem</span>
                    <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="s1">&#39;mass&#39;</span><span class="p">):</span>
                        <span class="n">line</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">mass</span>
                    <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="s1">&#39;epsilon&#39;</span><span class="p">):</span>
                        <span class="n">line</span><span class="p">[</span><span class="mi">6</span><span class="p">]</span> <span class="o">=</span> <span class="n">KCALMOL_2_K</span> <span class="o">*</span> <span class="n">item</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">epsilon</span>
                        <span class="n">line</span><span class="p">[</span><span class="mi">7</span><span class="p">]</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">sigma</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line_template</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">l</span><span class="o">=</span><span class="n">line</span><span class="p">))</span>
                <span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__write_empty__</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">text_tag</span><span class="p">)</span>
        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__write_bond_info__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">out</span><span class="p">):</span>
        <span class="n">text_tag</span> <span class="o">=</span> <span class="s1">&#39;# Bond_Info&#39;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">syst</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="c1"># writing section header</span>
            <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">text_tag</span><span class="p">))</span>
            <span class="c1"># writing total number of bonds</span>
            <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{0:&lt;6}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">syst</span><span class="o">.</span><span class="n">bonds</span><span class="o">.</span><span class="n">count</span><span class="p">))</span>
            <span class="n">line_template</span> <span class="o">=</span> <span class="s1">&#39;{l[0]:&lt;6d}{l[1]:&lt;6d}{l[2]:&lt;6d}{l[3]:&lt;9}{l[4]:&lt;6.3f}</span><span class="se">\n</span><span class="s1">&#39;</span>
            <span class="n">count</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="k">for</span> <span class="n">bond</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">syst</span><span class="o">.</span><span class="n">bonds</span><span class="p">:</span>
                <span class="n">tmp</span> <span class="o">=</span> <span class="s1">&#39;fixed&#39;</span>  <span class="c1"># Fixed bond is the only option for CASSANDRA V-1.2</span>
                <span class="n">line</span> <span class="o">=</span> <span class="p">[</span><span class="n">count</span><span class="p">,</span> <span class="n">bond</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">bond</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">tmp</span><span class="p">,</span> <span class="n">bond</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">r0</span><span class="p">]</span>
                <span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line_template</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">l</span><span class="o">=</span><span class="n">line</span><span class="p">))</span>
            <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__write_empty__</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">text_tag</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__write_angle_info__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">out</span><span class="p">):</span>
        <span class="n">text_tag</span> <span class="o">=</span> <span class="s1">&#39;# Angle_Info&#39;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">syst</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="c1"># writing section header</span>
            <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">text_tag</span><span class="p">))</span>
            <span class="c1"># writing total number of angles</span>
            <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{0:&lt;6}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">syst</span><span class="o">.</span><span class="n">angles</span><span class="o">.</span><span class="n">count</span><span class="p">))</span>
            <span class="n">count</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="k">for</span> <span class="n">angle</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">syst</span><span class="o">.</span><span class="n">angles</span><span class="p">:</span>
                <span class="n">line_template</span> <span class="o">=</span> <span class="s1">&#39;{l[0]:&lt;6d}{l[1]:&lt;6d}{l[2]:&lt;6d}{l[3]:&lt;6d}{l[4]:&lt;10}{l[5]:&lt;13.3f}&#39;</span>
                <span class="n">line</span> <span class="o">=</span> <span class="p">[</span><span class="n">count</span><span class="p">,</span> <span class="n">angle</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">angle</span><span class="o">.</span><span class="n">b</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> <span class="n">angle</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">tag</span><span class="p">]</span>
                <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">angle</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="s1">&#39;is_fixed&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">angle</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">is_fixed</span><span class="p">:</span>
                    <span class="n">addon</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;fixed&#39;</span><span class="p">,</span> <span class="n">angle</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">theta0</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">addon</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;harmonic&#39;</span><span class="p">,</span> <span class="n">angle</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">k</span><span class="p">,</span> <span class="n">angle</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">theta0</span><span class="p">]</span>
                    <span class="n">line_template</span> <span class="o">+=</span> <span class="s1">&#39;{l[6]:&lt;13.3f}&#39;</span>
                <span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
                <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line_template</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">l</span><span class="o">=</span><span class="n">line</span> <span class="o">+</span> <span class="n">addon</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__write_empty__</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">text_tag</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__write_intra_scaling__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">out</span><span class="p">):</span>
        <span class="n">format_line</span> <span class="o">=</span> <span class="s1">&#39;{:&lt;6.2f}{:&lt;6.2f}{:&lt;6.2f}{:&lt;6.2f}&#39;</span>
        <span class="c1"># writing section header</span>
        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;# Intra_Scaling&#39;</span><span class="p">))</span>
        <span class="c1"># writing vdW scaling:  1-2 1-3 1-4 1-N</span>
        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">format_line</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="c1"># writing charge scaling:  1-2 1-3 1-4 1-N</span>
        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">format_line</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__write_dihedral_info__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">out</span><span class="p">):</span>
        <span class="n">text_tag</span> <span class="o">=</span> <span class="s1">&#39;# Dihedral_Info&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__write_empty__</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">text_tag</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__write_improper_info__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">out</span><span class="p">):</span>
        <span class="n">text_tag</span> <span class="o">=</span> <span class="s1">&#39;# Improper_Info&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__write_empty__</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">text_tag</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__write_fragment_info__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">out</span><span class="p">):</span>
        <span class="c1"># writing section header</span>
        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">&#39;# Fragment_Info&#39;</span><span class="p">))</span>
        <span class="c1"># writing indexing</span>
        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;{:}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
        <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">syst</span><span class="o">.</span><span class="n">particles</span><span class="p">)</span>
        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;  &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">&#39;{}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">item</span><span class="p">)</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">]</span> <span class="o">+</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)))</span>
        <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__write_fragment_connectivity__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">out</span><span class="p">):</span>
        <span class="n">text_tag</span> <span class="o">=</span> <span class="s1">&#39;# Fragment_Connectivity&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__write_empty__</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">text_tag</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__to_tags__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">inpt</span><span class="p">):</span>
        <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mcf_tags</span><span class="p">)</span>
        <span class="n">idxs</span> <span class="o">=</span> <span class="p">[</span><span class="bp">True</span><span class="p">]</span> <span class="o">*</span> <span class="n">n</span>
        <span class="k">if</span> <span class="n">inpt</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;atoms&#39;</span><span class="p">:</span>
            <span class="n">idxs</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span><span class="p">]</span> <span class="o">*</span> <span class="n">n</span>
            <span class="n">idxs</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">mcf_tags</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="s1">&#39;# Atom_Info&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="n">idxs</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">mcf_tags</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="s1">&#39;# Intra_Scaling&#39;</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="k">return</span> <span class="n">idxs</span></div>


<div class="viewcode-block" id="check_cs_exec"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.check_cs_exec">[docs]</a><span class="k">def</span> <span class="nf">check_cs_exec</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;pysimm.cassandra.check_cs_exec</span>

<span class="sd">    Validates that the absolute path to the CASSANDRA executable is set in the `CASSANDRA_EXEC` environmental variable</span>
<span class="sd">    of the OS. The validation is called once inside the :class:`~Cassandra.run` method.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">global</span> <span class="n">CASSANDRA_EXEC</span>
    <span class="n">flag</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">if</span> <span class="n">CASSANDRA_EXEC</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
        <span class="k">print</span><span class="p">(</span><span class="s1">&#39;Please specify the OS environment variable &#39;&#39;CASSANDRA_EXEC&#39;&#39; that points to &#39;</span>
              <span class="s1">&#39;CASSANDRA compiled binary file, which is by default cassandra_{compiler-name}[_openMP].exe &#39;</span><span class="p">)</span>
        <span class="n">flag</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">return</span> <span class="n">flag</span></div>


<div class="viewcode-block" id="make_iterable"><a class="viewcode-back" href="../../pysimm.cassandra.html#pysimm.cassandra.make_iterable">[docs]</a><span class="k">def</span> <span class="nf">make_iterable</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.cassandra.make_iterable</span>

<span class="sd">    Utility method that forces the attributes be iterable (wrap in a list if it contains of only one item)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">it_obj</span> <span class="o">=</span> <span class="n">obj</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">Iterable</span><span class="p">):</span>
        <span class="n">it_obj</span> <span class="o">=</span> <span class="p">[</span><span class="n">obj</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">it_obj</span></div>

</pre></div>

           </div>
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2017, https://pysimm.org.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../',
            VERSION:'0.2',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="../../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>